package com.gmail.yesguxun.sample;

import java.io.IOException;
import java.util.List;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.util.Log;

public class UtilityGeo {
	
	static public void geocodeTest(Context context, String strAddress)
	{
	    String str;
		Geocoder gc = new Geocoder(context);
		List<Address> list = null;
		
		Log.i("abc","geo test");
		
		if(strAddress == null)
		{
		    str = "1600 Amphitheatre Parkway, Mountain View, CA";
		}
		else
		{
		    str = strAddress;
		}
		
        
		try {
	        list = gc.getFromLocationName(str, 1);
        } catch (IOException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        } 

	    Address address = list.get(0);

	    double lat = address.getLatitude();
	    double lng = address.getLongitude();
	    
	    Log.i("abc", "lat: " + lat + " lng: " + lng);
	}
	
	static public void geocodeReverseTest(Context context, double latitute, double longitude)
	{	
		Geocoder gc = new Geocoder(context);
		List<Address> list = null;
        try {
            list = gc.getFromLocation(latitute, longitude,1);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

		Address address = list.get(0);

		StringBuffer str = new StringBuffer();
		str.append("Name: " + address.getLocality() + "\n");
		str.append("Sub-Admin Ares: " + address.getSubAdminArea() + "\n");
		str.append("Admin Area: " + address.getAdminArea() + "\n");
		str.append("Country: " + address.getCountryName() + "\n");
		str.append("Country Code: " + address.getCountryCode() + "\n");

		String strAddress = str.toString();
		Log.i("abc", strAddress);
	}

}
